package net.aetherial.context.grounding.area51;

import java.io.*;
import java.util.*;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;

import org.rosuda.JRclient.*;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;

/*import opennlp.tools.lang.english.*;
import opennlp.tools.postag.TagDictionary;
import opennlp.tools.ngram.*;
import opennlp.tools.ngram.Dictionary; */

/**
 * Developer-only class used for troubleshooting code before transforming into a system object. Unused in the current version.
 */
public class Laboratory 
{
	/* public static void main (String[] args)
	{
		String[] input = { "hey patti",	"hey lauren", "hows it goin", "its well", "cool", "did you get to go to nca over the weekend",
				"yeah i did i saw you on fri remember", "i had a good time", "did you ", "uh huh",	"oh i meant on saturday or sunday",
				"ohh sorry", "gotcha", "yeah i didnt make it on saturday or sunday", 
				"but i emailed a couple of the presenters whose papers i was interested in", "cool",
				"so hopefully i can pick up some good bits of info through that", "yeah", "i think i met one of noshs former students on saturday",
				"oh really", "he calls him dr contractor", "haha",	"and i was thinking aw we call him nosh", "i know thats funny",
				"i wonder if we should call him dr instead", "but i thought first names were ok in grad school",
				"well at the tsb orientation bryan pardo was joking that we should call him herr doctor professor pardo",
				"kino actually said it with a straight face", "oh my goodness",	"that is so funny",	"poor kino", "yeah",
				"i actually dont think i know who brian pardo is",	"ive heard the name a lot before though", 
				"oh hes a cs prof who does a lot of music stuff", "ohh ok",	"he made a program that recognizes beatles tunes if you hum them",
				"no way", "thats pretty cool", "yeah it is", "what do you do with that though", "i dont know", "he made it into a cell phone game though",
				"so two people can try and see who scores higher", "ohh ok well thats something", "i want that", "i think its online", "oh nice",
				"i play the iLike game on facebook", "do you know what that is", "i havent tried it yet", "what does it do",
				"basically it gives you a random song and 4 multiple choice options", "and you have to guess either the artist or the song name",
				"you mean it plays the song", "and it keeps track of how well you do, how fast you can do it, etc", "yep", "that sounds fun",
				"like the facebook friend game", "its good for music buffs yeah exactly",
				"although sadly i know music better than i know my friends aparently", "the friend game is hard", "very random info",
				"haha it is" };
		
		System.out.println ("Input size: " + input.length);
		
		ArrayList<String> strings = new ArrayList<String> ();

		for (String s: input)
			strings.add (s);
		
		// PosTagger p = new PosTagger ("/home/cjkarr/Desktop/build.bin.gz", new Dictionary ("/home/cjkarr/Desktop/dict.bin.gz"), new TagDictionary ("/home/cjkarr/Desktop/tag.bin.gz"));
		
	} */
	
	/* public static void main (String[] args)
	{
		try 
		{
			BufferedReader r = new BufferedReader (new FileReader ("/Users/cjkarr/Desktop/regression.txt"));

			ArrayList<Double> college = new ArrayList<Double> ();
			ArrayList<Double> high = new ArrayList<Double> ();
			ArrayList<Double> sat = new ArrayList<Double> ();
			ArrayList<Double> ltr = new ArrayList<Double> ();

			String line = null;
			while ((line = r.readLine ()) != null)
			{
				String[] toks = line.split (" ");
				
				if (toks.length == 4)
				{
					try
					{
						college.add (Double.parseDouble (toks[0]));
						high.add (Double.parseDouble (toks[1]));
						sat.add (Double.parseDouble (toks[2]));
						ltr.add (Double.parseDouble (toks[3]));
					}
					catch (Exception e)
					{
						e.printStackTrace ();
					}
				}
			}
			
			Rconnection c = new Rconnection();
			
			double[] colleges = new double[college.size ()];
			double[] highs = new double[high.size ()];
			double[] sats = new double[sat.size ()];
			double[] ltrs = new double[ltr.size ()];
			
			for (int i = 0; i < college.size(); i++)
			{
				colleges[i] = college.get (i).doubleValue ();;
				highs[i] = high.get (i).doubleValue ();;
				sats[i] = sat.get (i).doubleValue ();;
				ltrs[i] = ltr.get (i).doubleValue ();;
			}
			
 			c.assign ("college", colleges);
 			c.assign ("high", highs);
 			c.assign ("sat", sats);
 			c.assign ("ltr", ltrs);
 			
 			c.voidEval("m<-lm(ltr~college+high+sat)");
 			double [] coeff = c.eval("coefficients(m)").asDoubleArray ();
 			
 			for (int i = 0; i < coeff.length; i++)
 			{
 				System.out.println ("cord["+ i + "] = " + coeff[i]);
 			}

		}
		catch (Exception e) 
		{
			e.printStackTrace();
		}
	} */
	
	public static void main (String[] args)
	{
		ArrayList<Double> codedValues = new ArrayList<Double> ();
		ArrayList<Double> predictedValues = new ArrayList<Double> ();
		
		String path = System.getProperty ("xml.chats.path");

		if (path == null)
			path = "/Users/cjkarr/Desktop/coded_chats";

		try 
		{

			File f = new File (path);

			if (f.isDirectory ())
			{
				DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance ();
				factory.setIgnoringElementContentWhitespace (true);
				
				DocumentBuilder builder = factory.newDocumentBuilder ();

				File[] children = f.listFiles ();

				for (File child: children)
				{
					if (child.getAbsolutePath().endsWith (".xml"))
					{
						Document d = builder.parse (child);
						
						NodeList list = d.getElementsByTagName ("turn");
						
						for (int i = 0; i < list.getLength (); i++)
						{
							Element turn = (Element) list.item (i);
							
							codedValues.add(Double.parseDouble (turn.getAttribute ("score")));
							predictedValues.add(new Double (i+1));
						}
					}
				}
			}
			
			System.out.print ("predict = c(");
			for (Double d: predictedValues)
				System.out.print (d + ",");
			System.out.println (")");
			
			System.out.print ("coded = c(");
			for (Double d: codedValues)
				System.out.print (d + ",");
			System.out.println (")");

		} 
		catch (Exception e) 
		{
			e.printStackTrace();
		}
	}
}
